package jp.gr.java_conf.ryz.summarize.client.presenter;

import java.util.ArrayList;
import java.util.List;


public class PostDecoration implements NotifyPropertyChanged
{
	public static final String DefaultFontSize = "";
	public static final String FontSizePropertyName = "_fontSize";
	public static final String IsBoldPropertyName = "_isBold";
	public static final String ColorPropertyName = "_color";
	
	private List<PropertyChangedHandler> _propertyChangedHandlers = new ArrayList<PropertyChangedHandler>();
	private String _fontSize;
	private boolean _isBold;
	private String _color;
	
	
	public PostDecoration()
	{
		init();
	}
	
	
	@Override
	public void addPropertyChangedHandler(PropertyChangedHandler handler)
	{
		_propertyChangedHandlers.add(handler);
	}

	@Override
	public void removePropertyChangedHandler(PropertyChangedHandler handler)
	{
		_propertyChangedHandlers.remove(handler);
	}
	
	public String getFontSize()
	{
		return _fontSize;
	}
	
	public void setFontSize(String fontSize)
	{
		if (fontSize.equals(_fontSize))
			return;
		
		_fontSize = fontSize;
		RaisePropertyChanged(this, FontSizePropertyName);
	}
	
	public String getFontSizeStyle()
	{
		String s = getFontSize();
		return s == null ? null : " font-size:" + s + "; ";
	}
	
	public boolean isBold()
	{
		return _isBold;
	}
	
	public void setIsBold(boolean isBold)
	{
		if (_isBold == isBold)
			return;
		
		_isBold = isBold;
		RaisePropertyChanged(this, IsBoldPropertyName);
	}
	
	public String getFontWeightStyle()
	{
		return isBold() ? " font-weight:bold; " : null;
	}
	
	public String getColor()
	{
		return _color;
	}
	
	public void setColor(String color)
	{
		if (color.equals(_color))
			return;
		
		_color = color;
		RaisePropertyChanged(this, ColorPropertyName);
	}
	
	public String getColorStyle()
	{
		String color = getColor();
		return color == null ? null : " color:" + color + "; ";
	}
	
	
	private void init()
	{
		
	}
	
	private void RaisePropertyChanged(Object sender, String propertyName)
	{
		for (PropertyChangedHandler each : _propertyChangedHandlers)
		{
			each.OnPropertyChanged(sender, propertyName);
		}
	}
}
